﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webnew.Model;
using webnew.Common;
namespace webnew.UserControls
{
    public partial class UcRoleCheckBox : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        /// <summary>
        /// 显示角色选项
        /// </summary>
        public void ShowCheckBox()
        {
            //binddata();
            System.Text.StringBuilder strSql = new System.Text.StringBuilder();
            strSql.Append("isdel=0 order by roleName  desc ");
            webnew.Common.CommonHelper.DataLbBind(chkRole, new BLL.Sys_Role().GetconList(strSql.ToString()), "roleName", "id");
        }

        public void binddata()
        {
            this.chkRole.Items.Clear();          
            System.Text.StringBuilder strSql = new System.Text.StringBuilder();
            strSql.Append("isdel=0 order by roleName  desc ");
            List<Sys_RoleInfo>  modelRole=  new BLL.Sys_Role().GetconList(strSql.ToString());
            foreach (Sys_RoleInfo model  in modelRole)
            {
                ListItem tm = new ListItem(" <a   href= 'http://www.yahoo.com '> " + model.rolename + " <a> ", model.Id);
               //tm.Attributes["onmousemove "] = "this.style.fontSize= '2cm '; ";
                this.chkRole.Items.Add(tm); 
            }
            
        }
        /// <summary>
        /// 显示角色选项，并选定当前用户的角色
        /// </summary>
        /// <param name="roleNameList"></param>
        public void ShowCheckBox(string userid)
        {
            this.ShowCheckBox();
             System.Data.DataTable dtUserRole = new BLL.Sys_UserRole().GetList(userid);
            for (int i = 0; i < chkRole.Items.Count; i++)
            {
                for (int j = 0; j < dtUserRole.Rows.Count; j++)
                {
                    if (chkRole.Items[i].Value == dtUserRole.Rows[j]["roleid"].ToString())
                    {
                        chkRole.Items[i].Selected = true;
                    }
                }
            }
            }

        
        /// <summary>
        /// 获取当前所有选定的角色
        /// </summary>
        /// <returns>返回角色数组</returns>
        public List<webnew.Model.Sys_UserRoleInfo> GetAllCheckedValue(string userid)
        {
           List<webnew.Model.Sys_UserRoleInfo> lstRole = new List<webnew.Model.Sys_UserRoleInfo>();
    
           
            for (int i = 0; i < chkRole.Items.Count; i++)
            {
                if (chkRole.Items[i].Selected)
                {
                    Model.Sys_UserRoleInfo tempModel= new Model.Sys_UserRoleInfo();
                    tempModel.UserID= userid;
                    tempModel.roleid =chkRole.Items[i].Value;
                    lstRole.Add(tempModel);
                }
            }
            return lstRole;
        }
    }
}